package com.twd.allcomponent.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ApiModel("统一返回VO")
public class ResultVO<T>
{
    @ApiModelProperty("状态码")
    private int status;

    @ApiModelProperty("消息")
    private String msg;

    @ApiModelProperty("数据体")
    private T data;

    // 接口成功返回的状态码
    private static final int SUCCESS_CODE = 0;

    public ResultVO(Integer status, String msg, T data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public ResultVO(Integer status, String msg) {
        this.status = status;
        this.msg = msg;
    }

    public ResultVO() {
        this(SUCCESS_CODE, "", null);
    }

    /**
     * 无返回值返回
     * @param <T> 类型
     * @return ApiRestResponse对象
     */
    public static <T> ResultVO<T> success() {
        return new ResultVO<>();
    }

    /**
     * 请求成功带返回值
     * @param result 返回值中的data信息
     * @param <T> 类型
     * @return ApiRestResponse对象
     */
    public static <T> ResultVO<T> success(T result) {
        ResultVO<T> response = new ResultVO<>();
        response.setData(result);
        return response;
    }

    /**
     * 失败时返回
     * @param code 状态码
     * @param msg  错误信息
     * @param <T> 类型
     * @return ApiRestResponse对象
     */
    public static <T> ResultVO<T> error(Integer code, String msg) {
        return new ResultVO<>(code, msg);
    }

//    /**
//     *  通过枚举返回错误信息
//     * @param exceptionEnum 错误码枚举
//     * @param <T> 类型
//     * @return ApiRestResponse对象
//     */
//    public static <T> ApiRestResponse<T> error(ApiExceptionEnum exceptionEnum) {
//        return new ApiRestResponse<>(exceptionEnum.getCode(), exceptionEnum.getMsg());
//    }

    public int getStatus()
    {
        return status;
    }

    public void setStatus(int status)
    {
        this.status = status;
    }

    public String getMsg()
    {
        return msg;
    }

    public void setMsg(String msg)
    {
        this.msg = msg;
    }

    public T getData()
    {
        return data;
    }

    public void setData(T data)
    {
        this.data = data;
    }
}